package com.yauta.freegift.service.logic.impl;

import java.util.HashMap;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yauta.freegift.service.dao.UserDAO;
import com.yauta.freegift.service.dto.UserQueryDTO;
import com.yauta.freegift.service.entity.UserDO;
import com.yauta.freegift.service.logic.IUserService;

@Service
public class UserServiceImpl implements IUserService {

	@Resource
	private SqlSession session;

	@Override
	public long addUser(UserDO user) {
		// TODO Auto-generated method stub
		UserDAO dao = session.getMapper(UserDAO.class);
		return dao.addUser(user);
	}

	@Override
	public HashMap<Long, UserDO> queryUser(int pageIndex, int limit) {
		// TODO Auto-generated method stub
		UserQueryDTO dto = new UserQueryDTO();
		dto.setPageIndex(pageIndex);
		dto.setPageSize(limit);
		UserDAO dao = session.getMapper(UserDAO.class);
		return dao.queryUser(dto);
	}

	@Override
	public UserDO getUserById(long id) {
		return session.getMapper(UserDAO.class).getUserById(id);
	}
	
	@Override
	public void deleteUser(long id)
	{
		session.getMapper(UserDAO.class).deleteUser(id);
	}

}
